define(['jquery', 'bootstrap', 'backend', 'table', 'form','xyvenue_vue'], function ($, undefined, Backend, Table, Form,Vue) {

    var Controller = {
        index: function () {
            new Vue({
                el: "#configIndex",
                data() {
                    return {
                        activeName: "basic",
                        configData: {
                            basic: [
                                {
                                    id: 'xyvenue',
                                    title: '通用配置',
                                    tip: '系统通用配置',
                                },
                                {
                                    id:'appstyle',
                                    title:'前端配置',
                                    tip: '配置前端主色调、导航栏色调，文字颜色等',
                                },
                            ],
                            platform: [
                                {
                                    id: 'wxminiprogram',
                                    title: '微信小程序',
                                    tip: '配置微信小程序',
                                },
                            ],
                            payment: [
                                {
                                    id: 'wechat',
                                    title: '微信支付',
                                    tip: '配置微信支付',
                                },
                            ],
                            other:[
                                
                                
                            ]
                        }
                    }
                },
                methods: {
                    tabClick(name) {
                        this.activeName = name;
                    },
                    operation(id, title) {
                        var that = this;
                        Fast.api.open("xyvenue/config/set?type=" + id + "&tab=" + that.activeName + "&title=" + title, title,{
                            area: ['80%', '80%']
                        });
                    },
                },
            })
        },
        set: function () {
            new Vue({
                el: "#configSet",
                data() {
                    return {
                        setData: {
                            xyvenue:{
                                name:'XYvenue场地预定',
                                store_id:'',
                                logo:'/assets/addons/xyvenue/imgs/logo.png',
                                useravatar:'/assets/addons/xyvenue/imgs/logo.png',
                                advancedays: 0,
                                dayhour:4,
                                returnhour:24,
                                holidays:'',
                                agreement:'',
                                privacy:''
                            },
                            
                            wxminiprogram: {
                                app_id: '',
                                secret: '',
                            },
                            wechat: {
                                mch_id: '',
                                key: '',
                                cert_client: '',
                                cert_key: '',
                            },
                            appstyle:{
                                mainColor:'#0069eb', //主色调
                                navBarBgColor:'#0069eb', //导航栏背景颜色
                                navBarFrontColor:'#ffffff', //导航栏字体颜色
                                pageBgColor:'#f7f7f7', //页面背景颜色
                                textMainColor:'#333333', //文字主色调
                                textLightColor:'#808080', //文字浅色调
                                textPriceColor:'#ff5335',//价格文字颜色
                            },
                        },
                        type: Config.type, 
                        tab: new URLSearchParams(location.search).get('tab'),
                        title: new URLSearchParams(location.search).get('title'),
                        detailForm: {},
                    }
                },
                mounted() {
                    this.operationData();
                },
                methods: {

                    operationData() {
                        this.detailForm = this.setData[this.type]
                        if (Config.row) {
                            console.log('Config.row',Config.row);
                            for (key in this.detailForm) {
                                if (Config.row[key]) {
                                    if (Config.row[key] instanceof Object) {
                                        for (inner in Config.row[key]) {
                                            if (Config.row[key][inner]) {
                                                this.detailForm[key][inner] = Config.row[key][inner]
                                            }
                                        }
                                    } else {
                                        this.detailForm[key] = Config.row[key]
                                    }
                                }
                            }
                        }
                    },
                    
                    submitFrom(type) {
                        var that = this; 
                        
                        if (type == 'yes') {
                            
                            var submitData = JSON.parse(JSON.stringify(that.detailForm))
                            
                            Fast.api.ajax({
                                url: 'xyvenue/config/set?type=' + that.type,
                                loading: true,
                                type: 'POST',
                                data: {
                                    data: JSON.stringify(submitData),
                                    group: that.tab,
                                    title: that.title
                                },
                            }, function (ret, res) {
                                Fast.api.close()
                            })
                        } else {
                            Fast.api.close()
                        }
                    },

                    attSelect(field,type = 'image') {
                        var that = this;
                        Fast.api.open("general/attachment/select?multiple=false", "选择图片", {
                            callback: function (data) {
                                switch (type) {
                                    case "image":
                                        that.detailForm[field] = data.url;
                                        break;
                                }
                            }
                        });
                        return false;
                    },

                    articleSelect(field,multiple = 'false'){
                        var that = this;
                        Fast.api.open("xyvenue/article/select?multiple="+multiple, "选择文章", {
                            callback: function (data) {
                                that.detailForm[field] = data.id;
                            }
                        });
                        return false;
                    },

                    storeSelect(field,multiple = 'false'){
                        var that = this;
                        Fast.api.open("xyvenue/store/store/select?multiple="+multiple, "选择门店", {
                            callback: function (data) {
                                that.detailForm[field] = data.id;
                            }
                        });
                        return false;
                    },

                    storeCancel(field){
                        this.detailForm[field] = '';
                    },

                    cdnurl(url){
					    var url = Fast.api.cdnurl(url);
                        if(url.substr(0,7).toLowerCase() == "http://" || url.substr(0,8).toLowerCase() == "https://"){
                            return url;
                        }else{
                            return window.location.protocol +'//'+ window.location.host + url;
                        }
					},
                    
                },
            })
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});